package com.huobao.yunying.adapters;

import java.util.Map;

import org.xutils.common.util.LogUtil;

import com.huobao.yunying.activitys.Act_Edit_Address;
import com.huobao.yunying.entity.My_address;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.zhangying.R;
import com.xrz.sxm.base.dialog.BaseDialog;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
import joanzapata.android.BaseAdapterHelper;
import joanzapata.android.QuickAdapter;

public class Adapter_Manager_Address extends QuickAdapter<My_address> {

	public Adapter_Manager_Address(Context context) {
		super(context, R.layout.item_manager_address);
	}

	@Override
	protected void convert(BaseAdapterHelper arg0, final My_address arg1) {
		arg0.setText(R.id.tv_name, arg1.consignee).setText(R.id.tv_number, arg1.phone_tel).setText(R.id.tv_address,
				arg1.region_name + " " + arg1.address);
		arg0.setOnClickListener(R.id.tv_edit, new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(context, Act_Edit_Address.class);
				intent.putExtra("data", arg1);
				((Activity)context).startActivityForResult(intent, 1);
			}
		}).setOnClickListener(R.id.tv_del, new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				BaseDialog.TBox("确定删除？", context, new BaseDialog.OnDialogSelectListener() {
					@Override
					public void onSelect(String input) {
						if(input.equals("true")){
							Map<String, String> map = HttpUtil.getParams("app","member","act","drop","addr_id",arg1.addr_id);
							Http.getInstant().sendRequest(context, map, new HttpListener() {

								@Override
								public void onHttpSuccess(String result) {
									LogUtil.e("删除----"+result);
									Toast.makeText(context, "删除成功！", Toast.LENGTH_SHORT).show();
									getList().remove(arg1);
									notifyDataSetChanged();
								}

								@Override
								public void onHttpError(String error) {
								}
							});
						}
					}
				});
			}
		});
	}

	
}
